package com.beordie.version_2.beans.support;

import com.beordie.version_2.beans.config.BODBeanDefinition;
import com.beordie.version_2.core.BODBeanFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Date 2022/2/14 8:32
 * @Created 30500
 */
public class BODDefaultListableBeanFactory implements BODBeanFactory {
    /**
     * 存储 class、name 到 beanDefinition 的映射
     */
    public Map<String, BODBeanDefinition> bodBeanDefinitionMap = new HashMap<>();

    @Override
    public Object getBean(Class beabClass) {
        return null;
    }

    @Override
    public Object getBean(String beanName) {
        return null;
    }

    /**
     * 转换映射方式
     * @param beanDefinitions
     */
    public void doRegistBeanDefinition(List<BODBeanDefinition> beanDefinitions) {
        for (BODBeanDefinition beanDefinition : beanDefinitions) {
            if (this.bodBeanDefinitionMap.containsKey(beanDefinition.getFactoryBeanName())) {
                throw new Error("this beanName " + beanDefinition.getFactoryBeanName() + "is exist.");
            }
            this.bodBeanDefinitionMap.put(beanDefinition.getFactoryBeanName(), beanDefinition);
        }
    }
}
